import gzip
from pathlib import Path

class LogFile:
    def __init__(self,filepath):
        self.filepath = filepath
        self.file = None
        self.openfile()
        pass

    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        if self.file is not None:
            self.file.close()
        return False
    def readline(self):
        return self.file.readline()

    def openfile(self):
        file_path = Path(self.filepath)
        if not file_path.exists():
            raise FileNotFoundError(self.filepath)
        if file_path.suffix == '.gz':
            self.file = gzip.open(self.filepath, 'rb')
        else:
            self.file = open(self.filepath,'rb')





